package com.dianpingmedia.common;


/**
 * 返回的错误码
 * Created by Karl He on 2017-05-27.
 */
public enum ErrorCode {
    UNKNOWN(-1),
    OK(0),
    FAIL(1),
    PARAMETER_ERROR(2),
    SYSTEM_ERROR(3),
    DUPLICATE(4),
    NOT_FOUND(5),
    NOT_LOGIN(6),
    PARAMETER_MISSING(7),
    DATA_FORMAT_ERROR(8),
    VERIFICATION_ERROR(9),
    CORRUPT_DATA(10),
    INVALID_COMMAND(11),
    COMMAND_TIMEOUT(12),
    PERMISSION_DENIED(13),
    NOT_ALLOWED_LOGIN(14),
    EXPIRED(15),
    NO_RESPONSE(16),
    RESPONSE_NOT_OK(17),
    BALANCE_NOT_ENOUGH(100),
    ACCOUNT_STATE_ABNORMAL(101),
    DEDUCT_FEE_FAIL(102),
    WRONG_PASSWORD(103),
    MATERIAL_NOT_FOUND(120),
    MATERIAL_MD5_ERROR(121),
    MATERIAL_NOT_REVIEWED(122),
    PERSISTENCE_OPERATION_FAIL(140),
    ORDER_NOT_FOUND(160),
    ORDER_STATE_ABNORMAL(161),
    SCREEN_NOT_FOUND(180),
    SCREEN_STATE_ABNORMAL(181),
    SCREEN_STATE_ERROR(182),
    ENCODING_NOT_SUPPORT(200),
    INVALID_DATA(201),
    INVALID_SIGNATURE(202),
    MISSING_TOKEN(203),
    TOKEN_NOT_FOUND(204),
    INVALID_TOKEN(205),
    VERIFY_TOKEN_FAIL(206),
    FILE_SIZE_THRESHOLD(220),
    SQL_ERROR(221),
    VERIFY_SIGN_FAIL(222),
    MATERIAL_EXIST(223);
    int value;

    ErrorCode(int value)
    {
        this.value = value;
    }

    public static ErrorCode valueOf(int value) { //手写的从int到enum的转换函数
        switch (value) {
            case -1:
                return UNKNOWN;
            case 0:
                return OK;
            case 1:
                return FAIL;
            case 2:
                return PARAMETER_ERROR;
            case 3:
                return SYSTEM_ERROR;
            case 4:
                return DUPLICATE;
            case 5:
                return NOT_FOUND;
            case 6:
                return NOT_LOGIN;
            case 7:
                return PARAMETER_MISSING;
            case 8:
                return DATA_FORMAT_ERROR;
            case 9:
                return VERIFICATION_ERROR;
            case 10:
                return CORRUPT_DATA;
            case 11:
                return INVALID_COMMAND;
            case 12:
                return COMMAND_TIMEOUT;
            case 13:
                return PERMISSION_DENIED;
            case 14:
                return NOT_ALLOWED_LOGIN;
            case 15:
                return EXPIRED;
            case 16:
                return NO_RESPONSE;
            case 17:
                return RESPONSE_NOT_OK;
            case 100:
                return BALANCE_NOT_ENOUGH;
            case 101:
                return ACCOUNT_STATE_ABNORMAL;
            case 102:
                return DEDUCT_FEE_FAIL;
            case 103:
                return WRONG_PASSWORD;
            case 120:
                return MATERIAL_NOT_FOUND;
            case 121:
                return MATERIAL_MD5_ERROR;
            case 122:
                return MATERIAL_NOT_REVIEWED;
            case 140:
                return PERSISTENCE_OPERATION_FAIL;
            case 160:
                return ORDER_NOT_FOUND;
            case 161:
                return ORDER_STATE_ABNORMAL;
            case 180:
                return SCREEN_NOT_FOUND;
            case 181:
                return SCREEN_STATE_ABNORMAL;
            case 182:
                return SCREEN_STATE_ERROR;
            case 200:
                return ENCODING_NOT_SUPPORT;
            case 201:
                return INVALID_DATA;
            case 202:
                return INVALID_SIGNATURE;
            case 203:
                return MISSING_TOKEN;
            case 204:
                return TOKEN_NOT_FOUND;
            case 205:
                return INVALID_TOKEN;
            case 206:
                return VERIFY_TOKEN_FAIL;
            case 220:
                return FILE_SIZE_THRESHOLD;
            case 221:
                return SQL_ERROR;
            case 222:
                return VERIFY_SIGN_FAIL;
            case 223:
                return MATERIAL_EXIST;

            default:
                return null;
        }
    }

    public int getValue()
    {
        return this.value;
    }
}
